// https://www.lintcode.com/problem/rotate-array/

class Solution {
public:
    /**
     * @param nums: an array
     * @param k: an integer
     * @return: rotate the array to the right by k steps
     */
    vector<int> rotate(vector<int> &nums, int k) {
        // 法一：旋转
        // int i = 0;
        // int n = nums.size();
        // k = k % n;
        // int cnt = n - k;
        // while (cnt--) nums.push_back(nums[i++]);
        // return vector<int>(nums.begin() + n - k, nums.end());
        
        // 法二：
        int n = nums.size();
        k = k % n;
        reverse(nums.begin(), nums.begin() + n - k);
        reverse(nums.begin() + n - k, nums.end());
        reverse(nums.begin(), nums.end());
        return nums;
    }
};